<template>
	<view class="">
		<block v-if="details.isLink">
			<web-view :src="details.url" />
		</block>
		<view class="content" v-else>
			<view class="tit">{{details.title}}</view>
			<view class="author">{{details.author}} <text class="col-gray">{{details.createTime}}</text> </view>
			<view v-html="details.content"></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				details: '',
				pagetype: ''
			}
		},
		onLoad(opt) {
			this.id = opt.id
			this.pagetype = opt.pagetype
			if (this.pagetype === '资讯详情') {
				this.getInformationDetails()
			} else {
				this.getPartyBuildingHistoryDetails()
			}
		},
		methods: {
			// 咨询详情
			async getInformationDetails() {
				const res = await this.$api.get(`article/info`, {
					id: this.id
				});
				// console.log(res, "资讯详情")
				if (res.code == 200) {
					var str = res.data.content;
					str = str.replace(/wscnph/g, 'wscnph maxImg');
					str = str.replace(/<img/g, '<img style="max-width:100% !important;height:auto;"');
					res.data.content = str;
					this.details = res.data

				}
			},
			// 党史要闻详情
			async getPartyBuildingHistoryDetails() {
				const res = await this.$api.get(`paper/new/${this.id}`, {});
				// console.log(res, "党史要闻详情")
				if (res.code == 200) {
					var str = res.data.content;
					str = str.replace(/wscnph/g, 'wscnph maxImg');
					str = str.replace(/<img/g, '<img style="max-width:100% !important;height:auto;"');
					res.data.content = str;
					this.details = res.data

				}
			},

		}
	}
</script>

<style lang="scss" scoped>
	.maxImg {
		width: 100%;
		max-width:100% !important;
		height:auto;
	}
	
	.tit {
		text-align: center;
		font-size: 30rpx;
		font-weight: bold;
		margin-bottom: 30rpx;
	}

	.content {
		padding: 30rpx;
		.author {
			font-size: 24rpx;
		}
		.col-gray {
			color: #999;
			margin-left: 20rpx;
		}
	}
</style>